{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Tce3stUlHN0L"
      },
      "source": [
        "##### Copyright 2025 Google LLC."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "tuOe1ymfHZPu"
      },
      "outputs": [],
      "source": [
        "# @title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
        "# you may not use this file except in compliance with the License.\n",
        "# You may obtain a copy of the License at\n",
        "#\n",
        "# https://www.apache.org/licenses/LICENSE-2.0\n",
        "#\n",
        "# Unless required by applicable law or agreed to in writing, software\n",
        "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
        "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
        "# See the License for the specific language governing permissions and\n",
        "# limitations under the License."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PzjeBM__IE1k"
      },
      "source": [
        "# Upload files to Google Colab\n",
        "\n",
        "<a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/examples/Upload_files_to_Colab.ipynb\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" height=30/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1vDOxWIpHPyD"
      },
      "source": [
        "You can upload files to Google Colab to quickly experiment with your own data. For example, you can upload video or image files to use with the Files API, or a upload a text file to read in with a long context model like Gemini Flash. This example shows you how to upload files to the Colab runtime and use them in your code.\n",
        "\n",
        "First, download the following file to your local machine:\n",
        "\n",
        "*  [a11.txt](https://storage.googleapis.com/generativeai-downloads/data/a11.txt)\n",
        "\n",
        "It contains a transcript of transmissions from the Apollo 11 mission, originally from https://www.nasa.gov/history/alsj/a11/a11trans.html.\n",
        "\n",
        "Next, upload the file to Google Colab. To do so, first click **Files** on the left sidebar, then click the **Upload** button:\n",
        "\n",
        "<img width=400 src=\"https://ai.google.dev/tutorials/images/colab_upload.png\">\n",
        "\n",
        "You're now able to use the file in Colab!"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "a90kMgiDvNlk"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "INTRODUCTION\n",
            "\n",
            "This is the transcription of the Technical Air-to-Ground Voice Transmission (GOSS NET 1) from the Apollo 11 mission.\n",
            "\n",
            "Communicators in the text may be identified according to the following list.\n",
            "\n",
            "Spacecraft:\n",
            "CDR\tCommander\tNeil A. Armstrong\n",
            "CMP\tCommand module pilot   \tMichael Collins\n",
            "LMP\tLunar module pilot\tEdwin E. ALdrin, Jr.\n"
          ]
        }
      ],
      "source": [
        "with open('a11.txt') as file:\n",
        "  text_data = file.read()\n",
        "\n",
        "# Print first 10 lines\n",
        "for line in text_data.splitlines()[:10]:\n",
        "  print(line)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HxFNPBonwZc3"
      },
      "source": [
        "This makes it simple to use the file with the Gemini API."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "id": "_d_yY8XWGQ12"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/137.7 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r",
            "\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━\u001b[0m \u001b[32m133.1/137.7 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m137.7/137.7 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25h"
          ]
        }
      ],
      "source": [
        "%pip install -U -q \"google-genai>=1.0.0\""
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "l8g4hTRotheH"
      },
      "source": [
        "To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication ![image](https://storage.googleapis.com/generativeai-downloads/images/colab_icon16.png)](../quickstarts/Authentication.ipynb) for an example."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "id": "iWd---jVKV5M"
      },
      "outputs": [],
      "source": [
        "from google.colab import userdata\n",
        "from google import genai\n",
        "\n",
        "GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
        "client = genai.Client(api_key=GOOGLE_API_KEY)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "11dbc57d09f2"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Based on the provided text, this is a transcript of air-to-ground voice communications from the Apollo 11 mission. It includes:\n",
            "\n",
            "*   **Introduction:** Explains the document is a transcription of GOSS NET 1 (Technical Air-to-Ground Voice Transmission) for Apollo 11. It lists abbreviations used for different speakers (Commander, Command Module Pilot, Lunar Module Pilot, various ground control and recovery personnel).\n",
            "\n",
            "*   **Abbreviations Key:** Provides a key to understand who the different communicators are (e.g., CDR = Commander, CMP = Command Module Pilot, CC = Capsule Communicator).\n",
            "\n",
            "*   **Air-to-Ground Voice Transcription:** The main body of the document, which is the transcribed dialogue between the Apollo 11 astronauts and mission control in Houston, as well as other ground stations. The text is segmented by timecode and location (e.g., MILA, GRAND BAHAMA ISLANDS, CANARY). It covers various aspects of the mission from launch to initial post-splashdown communications.\n",
            "\n",
            "In short, this is the official record of what was said between the Apollo 11 crew and ground control during the mission, providing a detailed account of procedures, observations, and conversations.\n",
            "\n"
          ]
        }
      ],
      "source": [
        "MODEL_ID = \"gemini-2.5-flash\" # @param [\"gemini-2.5-flash-lite\", \"gemini-2.5-flash\", \"gemini-2.5-pro\",\"gemini-3-pro-preview\"] {\"allow-input\":true, isTemplate: true}\n",
        "response = client.models.generate_content(\n",
        "    model=MODEL_ID,\n",
        "    contents=[\n",
        "        'What is this transcript?',\n",
        "        text_data\n",
        "    ]\n",
        ")\n",
        "print(response.text)"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "name": "Upload_files_to_Colab.ipynb",
      "toc_visible": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
